<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生成绩</title>
    <link rel="stylesheet" href="/css/layui.css">
</head>
<body>
<!-- 表格 -->
<table class="layui-hide" id="teacherStuScore" lay-filter="teacherStuScoreFilter"></table>

<!-- 头部工具栏 -->
<script type="text/html" id="TeacherScoreToolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i>添加学生成绩</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="deleteAll" ><i class="layui-icon layui-icon-delete"></i>批量删除</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>

<!-- 行工具栏 -->
<script type="text/html" id="TeacherScoreBar">
    <a class="layui-btn layui-btn-xs" lay-event="update"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<!-- 弹出修改界面 -->
<form class="layui-form" id="TeacherStuScoreUpdate" style="display: none" lay-filter="TeacherStuScoreUpdate">
    <form class="layui-form" action="" lay-filter="addStuScore">
        <div class="layui-form-item" style="visibility: hidden">
            <label class="layui-form-label">学生编号</label>
            <div class="layui-input-inline">
                <input type="text" name="id" lay-verify="required" lay-reqText="请输入正确的学号" placeholder="请输入学号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学生学号</label>
            <div class="layui-input-inline">
                <input type="text" name="studentId" lay-verify="required" lay-reqText="请输入正确的学号" placeholder="请输入学号" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">班级</label>
            <div class="layui-input-inline">
                <input type="text" name="classesId" lay-verify="title" autocomplete="off" placeholder="请输入姓名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科目</label>
            <div class="layui-input-inline">
                <select name="subjectId">
                    <option value="">请选择科目</option>
                    <option value="1">语文</option>
                    <option value="2">数学</option>
                    <option value="3">英语</option>
                    <option value="4">物理</option>
                    <option value="5">化学</option>
                    <option value="6">生物</option>
                    <option value="7">地理</option>
                    <option value="8">历史</option>
                    <option value="9">政治</option>
                    <option value="10">体育</option>
                </select>
            </div>
            <label class="layui-form-label">科目老师</label>
            <div class="layui-input-inline">
                <select name="teacherId">
                    <option value="">请选择科目老师</option>
                    <option value="1">文章</option>
                    <option value="3">数学王者</option>
                    <option value="4">物理大神</option>
                    <option value="5">化学牛人</option>
                    <option value="7">生物教授</option>
                    <option value="9">历史时钟</option>
                    <option value="10">政治角斗士</option>
                    <option value="13">地理游客</option>
                    <option value="15">体育达人</option>
                    <option value="16">英语健将</option>
                    <option value="17">杂家</option>
                    <option value="19">全才</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">分数</label>
            <div class="layui-input-inline">
                <input type="text" name="score"  placeholder="请输入分数" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">考试时间</label>
            <div class="layui-input-inline">
                <input type="date" name="testTime"  placeholder="请输入考试时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-form-item" style="text-align: center">-->
            <!--<button  class="layui-btn" lay-submit lay-filter="doSubmit">新增</button>-->
            <!--<input type="reset" class="layui-btn" >重置</input>-->
        <!--</div>-->
    </form>
    </div>
</form>

</body>
<script src="/layui.js" charset="utf-8"></script>
<script>
    layui.use(['table','layer','form'],function(){
        let table = layui.table;
        let layer=layui.layer;
        let form=layui.form;

        table.render({
            elem: '#teacherStuScore'
            ,url:'/teacher/queryStuScore'
            ,toolbar: "#TeacherScoreToolbar"
            ,title: '学生成绩表'
            ,totalRow: true
            ,cols: [  [
                {type: 'checkbox', fixed: 'left', totalRowText: '合计行',align:'center'}
                ,{field:'id', title:'编号', width:80, fixed: 'left', unresize: true, sort: true,align:'center'}
                ,{field:'studentInfo',width:120, title: '学生姓名',align:'center', sort: true, templet:function (res) {
                        return res.studentInfo.studentName;
                    }}
                ,{field:'subjectInfo',width:120, title: '科目',align:'center',templet:function (res) {
                        return res.subjectInfo.subjectName;
                    }}
                ,{field:'teachers',width:150, title: '科目老师',align:'center',templet:function (res) {
                        return res.teachers.teachersName;
                    }}
                ,{field:'score', width:120,title: '分数',align:'center'}
                ,{field:'testTime', width:150,title: '考试时间',align:'center'}
                ,{title:"操作",toolbar:"#TeacherScoreBar" ,width:150,fixed:'right',align:'center'}
            ]  ]
            ,page: true
            ,response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.items //解析数据列表
                };
            }
        });

        //监听头部工具栏事件
        table.on("toolbar(teacherStuScoreFilter)",function (obj) {
            switch (obj.event) {
                case 'add':
                    openAddStuScore();
                    break;
                case 'deleteAll':
                    // openUpdateStu();
                    break;
            }
        });

        //监听行工具栏事件
        table.on('tool(teacherStuScoreFilter)',function (obj) {

            switch (obj.event) {
                case 'update':
                    openUpdateStuScore(obj.data);
                    break;
                case 'delete':
                    if (TeacherDeleteStuScore(obj.data)){
                        obj.del();
                    }
                    break;
            }
        });

        function openAddStuScore() {
            layer.open({
                type:2,//弹出层类型
                title:"添加学生成绩",
                area:['800px','600px'],
                content:'http://localhost:8080/teachers/TeacherAddStuScore.html',
                success:function () {
                    $("#addStuScore")[0].reset()
                }
            })
        }

        let url;//提交地址
        let mainIndex;//窗口索引
        function openUpdateStuScore(data) {
            mainIndex= layer.open({
                type:1,//弹出层类型
                title:"修改学生信息",
                area:['800px','600px'],
                shade: 0,
                btn: ['提交', '重置'],
                btn1: function(index, layero){
                    let data = form.val("TeacherStuScoreUpdate");
                    $.post("/teacher/modifyStuScore",data,function (res) {
                        if (res.success=="true"){
                            layer.alert("修改成功！",{icon:6,time:2000})
                        }
                    });
                    layer.closeAll();
                    return true;
                },btn2: function(index, layero){
                    $("#TeacherStuScoreUpdate")[0].reset();
                    return false;
                },
                cancel: function(layero,index){
                    layer.closeAll();
                },
                content:$("#TeacherStuScoreUpdate"),
                success:function () {
                    //表单数据回显
                    form.val("TeacherStuScoreUpdate",data);
                }
            })

        }
        function TeacherDeleteStuScore(data) {
            layer.confirm("确定删除吗？",{icon:3,title:"提示"},function (deleteStuScore) {
                $.post("/teacher/deleteStuScore",{id:data.id},function (res) { // "id="+data.id
                    if (res.success=="true"){
                        layer.alert("删除成功！",{icon:6,time: 2000});
                        layer.close(deleteStuScore);
                        return true;
                    } else{
                        layer.alert(res.msg,{icon:5,time: 2000});
                        layer.close(deleteStuScore);
                        return false;
                    }
                })
            })

        }
    });
</script>
</html>